home *** CD-ROM | disk | FTP | other *** search
- page 132,63,1,1
- opt rc
- title 'FFT transform and periodogram calculation'
-
- ;***************************************************************
- ;* FFT.ASM -- FFT transform, periodogram calculation and *
- ;* main control loop *
- ;* *
- ;* Provides main control loop of the FFT based periodogram *
- ;* spectrum analyzer. *
- ;* *
- ;* Periodogram calculation is based on the book: *
- ;* Oppenheim, A, Shafer, R.: *
- ;* "Digital Signal Processing", *
- ;* Prentice-Hall, 1975 *
- ;* *
- ;* This module uses registers as follows: *
- ;* r0 - *
- ;* r1 - *
- ;* r4 - *
- ;* r5 - *
- ;* r6 - *
- ;* *
- ;* Copyright (C) 1991 by Alef Null. All rights reserved. *
- ;* Author(s): Jarkko Vuori, OH2LNS *
- ;* Modification(s): *
- ;***************************************************************
-
- nolist
- include 'ioequlc'
- list
-
- section FFT
- xdef ssi_ini,fft_i
- xdef m_loop
- xref m_cra,m_crb,m_tde,m_sr,m_tx
-
- org p:
-
- nolist
- include 'macros'
- include 'fftr2a'
- list
-
- points equ 1024
-
- ; multiply p:(r0) (data) by p:(r1) (window) and
- ; put the result to x/y:(r2) (destination)
- winblk macro dest
- move p:(r0)+,x0
- move p:(r1)+,x1
- mpyr x0,x1,a
- do #points-1,_endloop
- move p:(r0)+,x0
- move p:(r1)+,x1
- mpyr x0,x1,a a,dest:(r2)+
- _endloop
- move a,dest:(r2)+
- endm
-
-
- ;****************************
- ;* SSI initialization *
- ;****************************
- ssi_ini
- ; initialize SSI,
- IF !DEBUG
- movep #$4000,x:m_cra ; 16 bit word
- movep #$f200,x:m_crb ; syncronous,word frame,ext clk
- ELSE
- movep #$4011,x:m_cra ; 16 bit word, abt. 19.2 ksamples/s
- movep #$f620,x:m_crb ; syncronous,word frame,ext clk
- ENDIF
-
- rts
-
-
- ;****************************
- ;* ADC & FFT *
- ;* initialization *
- ;****************************
- fft_i
- ; program the A/D & D/A converter chip (TLC32044, master clock is 5.184MHz)
- ; disable A/D high-pass filter, disable loopback, disable AUX IN,
- ; select syncronous mode, select input span 3Vpp, insert sinx/x correction
- ; lowpass cutoff frequency at 3600Hz -> TA = 9 (SCF = 288kHz)
- ; sampling frequency is 8000Hz -> TB = 36
- ; unit sampling correction time 0.4uS -> TA' = 2
- pgmtlc %10101001,9,2,36
-
- ; initialize input sample pointers
- move #samples,r7
- move #points-1,m7
-
- ; and FFT average counter
- move p:NN2,a
- move a,y:<count
- rts
-
-
- ;****************************
- ;* Main Loop *
- ;****************************
- loop wait
- m_loop
-
- ; check if one block converted
- move #>samples,x0
- move r7,a
- cmp x0,a x0,r0
- jne <loop
-
- ; yes, multiply samples with window
- move #window,r1
- move #data,r2
- move #-1,m1
- move m1,m2
-
- bchg #blksel,x:<status
- jcc <fft1
- winblk x
- jmp <loop
- fft1 winblk y
-
- ; real and imaginary banks filled, so transform data
- ; 129000 cycles, 6.22 mS
- fftr2a points,data,coef
-
- ; extract, scale and accumulate data
- ; select accumulator
- move #accb,r0
- jset #accsel,x:<status,fft2
- move #acca,r0
- fft2
-
- ; extract and take square
- ; 1/4[(Zr(k)+Zr(N-k))^2 + (Zi(k)-Zi(N-k))^2 + Zi(N-k)+Zi(k))^2 + Zr(N-k)-Zr(k))^2]
- ; = 1/2[Zr(k)^2 + Zi(k)^2 + Zr(N-k)^2 + Zi(N-k)^2]
- move #data,r1
- move #data+points-1,r2
- move #points/2,n1
- move n1,n2
- move #0,m1
- move m1,m2
-
- move x:(r1),x0
- do #points/2,endcopy ; k = 0..N/2
- mpy x0,x0,a y:(r1)+n1,y0 ; Zr(k)^2 + Zi(k)^2
- mac y0,y0,a x:(r2),x0 ; Zr(N-k)^2 + Zi(N-k)^2
- mac x0,x0,a y:(r2)-n2,y0
- macr y0,y0,a #@pow(2,-11-4),x0
- move a,x1
- mpy x0,x1,a
- move p:(r0),x0 ; add to result
- add x0,a
- rnd a x:(r1),x0
- move a,p:(r0)+
- endcopy
-
- ; check if enought integrated
- move y:<count,a
- move #>1,x0
- sub x0,a #>accb,x0
- move a,y:<count
- jne <loop
-
- ; yes, send result to host
- move p:NN2,a
- move a,y:<count
-
- jset #accsel,x:<status,fft4
- move #>acca,x0
- fft4 move #>points/2,a
- add x0,a
- move a,x1
-
- bchg #$2,x:m_pcd
- jsr <putblk
-
- ; change to new accumulator, and clear it
- clr a #acca,r0
- bchg #accsel,x:<status
- jcs <fft5
- move #accb,r0
- fft5 do #points/2,_endloop
- move a,p:(r0)+
- _endloop
-
- jmp <loop
-
-
- ;****************************
- ;* DATA - AREA *
- ;****************************
-
- org y:
-
- count ds 1
-
- endsec
-
- end
-